//
//  EarnViewController.m
//  LOU
//
//  Created by iMacOne on 15/11/6.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "EarnViewController.h"
#import "Size.h"
#import "ToolUtil.h"
#import "BaseView.h"
@interface EarnViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewAccessibilityDelegate>

@property (nonatomic,retain) NSArray *arr;
@property (nonatomic,retain) UIScrollView *scrollSmall;
@property (nonatomic,retain) UIScrollView *scrollDig;

@end

@implementation EarnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden = YES;
    [self createTitle:@"我的" midTitle:@"佣金攻略"];
    [ToolUtil createLine:margin_64 superView:self.view lift:0 width:WindowWidth hight:0.5 color:[UIColor grayColor]];

    [ToolUtil createLine:95 superView:self.view lift:0 width:WindowWidth hight:0.5 color:[UIColor cyanColor]];
    self.arr = @[@"卖房赚钱",@"邀请码",@"保护期"];
    
    //小scroll
    self.scrollSmall = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 65, self.view.frame.size.width, 30)];
    [self.view addSubview:self.scrollSmall];
    //self.scrollSmall.backgroundColor = [UIColor blueColor];
    
    UIView *img = [[UIView alloc] initWithFrame:CGRectMake(100, 0, self.scrollSmall.frame.size.width/2, self.scrollSmall.frame.size.height)];
    img.backgroundColor = [UIColor redColor];
    [self.scrollSmall addSubview:img];
    
    self.scrollSmall.contentSize = CGSizeMake(375, 0);
    self.scrollSmall.pagingEnabled = YES;
    self.scrollSmall.showsHorizontalScrollIndicator = NO;
    self.scrollSmall.contentOffset = CGPointMake(0, 0);
    
    for (int i = 0; i < 3; i++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(i*375/3, 0, 373/3, self.scrollSmall.frame.size.height);
        [button setTitle:self.arr[i] forState:UIControlStateNormal];
        [self.scrollSmall addSubview:button];
        [button addTarget:self action:@selector(Earn:) forControlEvents:7];
        button.tag = 40+i;
        if (i == 0) {
            button.backgroundColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            button.tintColor = [UIColor whiteColor];
        }else {
            button.backgroundColor = [UIColor whiteColor];
            button.tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
        }
    }
    
    self.scrollDig = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 96, self.view.frame.size.width, self.view.frame.size.height-95)];
    [self.view addSubview:self.scrollDig];
    self.scrollDig.contentSize = CGSizeMake(375*3, 0);
    self.scrollDig.pagingEnabled = YES;
    self.scrollDig.showsHorizontalScrollIndicator = NO;
    self.scrollDig.contentOffset = CGPointMake(0, 0);
    self.scrollDig.tag = 55;
    self.scrollDig.delegate = self;
    for (int j = 0; j < 3; j++) {
        
        UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(j*375, 0, self.scrollDig.frame.size.width, self.scrollDig.frame.size.height)];
        [self.scrollDig addSubview:table];
        table.dataSource = self;
        table.delegate = self;
        table.tag = 50+j;
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 15;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 50) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ccc"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ccc"];
        }
        cell.textLabel.text = @"666666666666";
        return cell;
    }else if (tableView.tag == 51) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ddd"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ddd"];
        }
        cell.textLabel.text = @"555555555555";
        return cell;
    }else if (tableView.tag == 52) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"eee"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"eee"];
        }
        cell.textLabel.text = @"44444444444444";
        return cell;
    }else {
        return 0;
    }
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.tag == 55) {
        NSLog(@"909090");

        if (self.scrollDig.contentOffset.x == 0) {
            [self.view viewWithTag:40].backgroundColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            [self.view viewWithTag:40].tintColor = [UIColor whiteColor];
            
            [self.view viewWithTag:41].backgroundColor = [UIColor whiteColor];
            [self.view viewWithTag:41].tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            
            [self.view viewWithTag:42].backgroundColor = [UIColor whiteColor];
            [self.view viewWithTag:42].tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            
        }
        if (self.scrollDig.contentOffset.x == 375) {
            [self.view viewWithTag:41].backgroundColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            [self.view viewWithTag:41].tintColor = [UIColor whiteColor];
            
            [self.view viewWithTag:40].backgroundColor = [UIColor whiteColor];
            [self.view viewWithTag:40].tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            
            [self.view viewWithTag:42].backgroundColor = [UIColor whiteColor];
            [self.view viewWithTag:42].tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
        }
        if (self.scrollDig.contentOffset.x == 375*2) {
            [self.view viewWithTag:42].backgroundColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            [self.view viewWithTag:42].tintColor = [UIColor whiteColor];
            
            [self.view viewWithTag:41].backgroundColor = [UIColor whiteColor];
            [self.view viewWithTag:41].tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
            
            [self.view viewWithTag:40].backgroundColor = [UIColor whiteColor];
            [self.view viewWithTag:40].tintColor = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
        }
    }
    
    //self.scrollSmall.contentOffset = CGPointMake(self.scrollDig.contentOffset.x / self.view.frame.size.width * self.view.frame.size.width / 3,0);
}

//-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
//{
//    if (scrollView.tag == 55) {
//        NSLog(@"00 %s",__func__);
//    }
//    
//}
//-(void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    if (scrollView.tag == 55) {
//        NSLog(@"11 %s",__func__);
//    }
//}
//
//-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
//{
//    if (scrollView.tag == 55) {
//        NSLog(@"22 %s",__func__);
//    }
//}
//-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
//    if (scrollView.tag == 55) {
//        NSLog(@"33 %s",__func__);
//        NSLog(@"x = %f, y = %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
//    }
//
//    
//}


-(void)Earn:(UIButton *)button
{
    UIColor *white = [UIColor whiteColor];
    UIColor *lang = [UIColor colorWithRed:41.96f/255.0f green:65.76f/255.0f blue:103.85f/255.0f alpha:1];
    if (button.tag == 40) {
        NSLog(@"1");
        self.scrollDig.contentOffset = CGPointMake(0, 0);
        if (button.tintColor != white) {
            button.tintColor = white;
            button.backgroundColor = lang;
            for (int j=40; j<43; j++) {
                if (j != 40) {
                    [self.view viewWithTag:j].tintColor = lang;
                    [self.view viewWithTag:j].backgroundColor = white;
                }
            }
        }
    }
    if (button.tag == 41) {
        NSLog(@"2");
        self.scrollDig.contentOffset = CGPointMake(self.view.frame.size.width*1, 0);
        if (button.tintColor != white) {
            button.tintColor = white;
            button.backgroundColor = lang;
            for (int j=40; j<43; j++) {
                if (j != 41) {
                    [self.view viewWithTag:j].tintColor = lang;
                    [self.view viewWithTag:j].backgroundColor = white;
                }
            }
        }
    }
    if (button.tag == 42) {
        NSLog(@"3");
        self.scrollDig.contentOffset = CGPointMake(self.view.frame.size.width*2, 0);
        if (button.tintColor != white) {
            button.tintColor = white;
            button.backgroundColor = lang;
            for (int j=40; j<43; j++) {
                if (j != 42) {
                    [self.view viewWithTag:j].tintColor = lang;
                    [self.view viewWithTag:j].backgroundColor = white;
                }
            }
        }
    }
}



@end
